<template>
  <div class="full">
    <ul class="extracted">
      <li v-for="(item, index) in randomLists" :key="index">
        {{item}}
      </li>
    </ul>
    <div class="random_box">{{randomNo}}</div>
    <div class="btn_group">
      <el-button type="primary" @click="start">开始</el-button>
      <el-button type="warning" @click="stop">暂停</el-button>
    </div>
  </div>
</template>

<script>
  export default {
    name: "index",
    components: {},
    props: {},
    data() {
      return {
        randomLists: localStorage.getItem('random') ? localStorage.getItem('random').split(',') : [],
        randomNo: '',
        timer: null
      };
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {},
    destroyed() {},
    methods: {
      getRandom() {
        let randomNo = Math.floor(Math.random() * 100);
        if (randomNo < 10) {
          console.log(randomNo)
          randomNo = '0' + randomNo;
        }
        this.randomNo = randomNo;
      },
      start() {
        window.clearInterval(this.timer);
        this.timer = setInterval(() => {
          this.getRandom();
        }, 100);
      },
      stop() {
        window.clearInterval(this.timer);
        this.randomLists.push(this.randomNo);
        localStorage.setItem('random', this.randomLists);
      }
    }
  }
</script>

<style scoped>

</style>
